package javango.contrib.admin;

import java.io.Serializable;
import java.util.Map;

import javango.contrib.hibernate.DaoException;
import javango.contrib.hibernate.ModelDao;

public class BaseBusinessLogic<T> implements BusinessLogic<T> {
	
	protected Class clazz;
	protected ModelDao<T> dao;
	
	public BaseBusinessLogic(Class clazz, ModelDao dao) {
		super();
		this.clazz = clazz;
		this.dao = dao;
	}

	
	public T get(Serializable pk) throws Exception {
		return dao.get(pk);
	}


	public Object getPk(T bean) throws Exception {
		return dao.getPk(bean);
	}


	public boolean canCreate() {
		return true;
	}

	public boolean canDelete(Object bean) {
		return true;
	}

	public boolean canUpdate(Object bean) {
		return true;
	}

	public T create(T bean) throws Exception {
		try {
			dao.save(bean);
			return bean;
		} catch (DaoException e) {
			throw new Exception(e);
		}
	}

	public boolean delete(Object bean) throws Exception {
		try {
			dao.delete(bean);
			return true;
		} catch (DaoException e) {
			throw new Exception(e);
		}
	}

	public Map<String, String> getErrors() {
		return null;
	}

	public T update(T bean) {
		return bean;
	}

}
